<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <!-- 统计卡片 -->
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon product">
              <el-icon size="24"><Goods /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ stats.productCount }}</div>
              <div class="stat-label">商品总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon order">
              <el-icon size="24"><Document /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ stats.orderCount }}</div>
              <div class="stat-label">订单总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon member">
              <el-icon size="24"><User /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ stats.memberCount }}</div>
              <div class="stat-label">会员总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon revenue">
              <el-icon size="24"><Money /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">¥{{ stats.totalRevenue }}</div>
              <div class="stat-label">总销售额</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <el-row :gutter="20" style="margin-top: 20px;">
      <!-- 销售趋势图 -->
      <el-col :span="16">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>销售趋势</span>
            </div>
          </template>
          <div class="chart-container">
            <div class="chart-placeholder">
              <el-icon size="48" color="#ccc"><TrendCharts /></el-icon>
              <p>销售趋势图表</p>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <!-- 商品分类占比 -->
      <el-col :span="8">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>商品分类占比</span>
            </div>
          </template>
          <div class="chart-container">
            <div class="chart-placeholder">
              <el-icon size="48" color="#ccc"><PieChart /></el-icon>
              <p>商品分类饼图</p>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <el-row :gutter="20" style="margin-top: 20px;">
      <!-- 最近订单 -->
      <el-col :span="12">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>最近订单</span>
            </div>
          </template>
          <el-table :data="recentOrders" style="width: 100%">
            <el-table-column prop="orderNo" label="订单号" width="150" />
            <el-table-column prop="memberName" label="会员" width="100" />
            <el-table-column prop="totalAmount" label="金额" width="100">
              <template #default="{ row }">
                ¥{{ row.totalAmount }}
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="100">
              <template #default="{ row }">
                <el-tag :type="getOrderStatusType(row.status)">
                  {{ getOrderStatusText(row.status) }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" />
          </el-table>
        </el-card>
      </el-col>
      
      <!-- 库存预警 -->
      <el-col :span="12">
        <el-card>
          <template #header>
            <div class="card-header">
              <span>库存预警</span>
            </div>
          </template>
          <el-table :data="lowStockProducts" style="width: 100%">
            <el-table-column prop="productName" label="商品名称" />
            <el-table-column prop="skuName" label="SKU" width="120" />
            <el-table-column prop="stock" label="库存" width="80">
              <template #default="{ row }">
                <el-tag type="danger">{{ row.stock }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="lowStock" label="预警值" width="80" />
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'

// 统计数据
const stats = ref({
  productCount: 1256,
  orderCount: 8934,
  memberCount: 4567,
  totalRevenue: '1,234,567'
})

// 最近订单
const recentOrders = ref([
  {
    orderNo: 'ORD20240101001',
    memberName: '张三',
    totalAmount: 299.00,
    status: 2,
    createTime: '2024-01-01 10:30:00'
  },
  {
    orderNo: 'ORD20240101002',
    memberName: '李四',
    totalAmount: 599.00,
    status: 3,
    createTime: '2024-01-01 11:15:00'
  },
  {
    orderNo: 'ORD20240101003',
    memberName: '王五',
    totalAmount: 199.00,
    status: 1,
    createTime: '2024-01-01 14:20:00'
  }
])

// 库存预警商品
const lowStockProducts = ref([
  {
    productName: 'iPhone 15 Pro',
    skuName: '深空黑色 256GB',
    stock: 5,
    lowStock: 10
  },
  {
    productName: 'MacBook Pro',
    skuName: '银色 16GB',
    stock: 3,
    lowStock: 8
  },
  {
    productName: 'AirPods Pro',
    skuName: '白色',
    stock: 2,
    lowStock: 15
  }
])

// 获取订单状态类型
const getOrderStatusType = (status: number) => {
  const types = ['', 'warning', 'primary', 'success', 'info', 'danger']
  return types[status] || 'info'
}

// 获取订单状态文本
const getOrderStatusText = (status: number) => {
  const texts = ['', '待付款', '待发货', '待收货', '已完成', '已取消']
  return texts[status] || '未知'
}

onMounted(() => {
  // 这里可以调用API获取实际数据
  console.log('仪表盘数据加载完成')
})
</script>

<style lang="scss" scoped>
.dashboard {
  .stat-card {
    .stat-content {
      display: flex;
      align-items: center;
      
      .stat-icon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16px;
        
        &.product {
          background-color: #e3f2fd;
          color: #1976d2;
        }
        
        &.order {
          background-color: #f3e5f5;
          color: #7b1fa2;
        }
        
        &.member {
          background-color: #e8f5e8;
          color: #388e3c;
        }
        
        &.revenue {
          background-color: #fff3e0;
          color: #f57c00;
        }
      }
      
      .stat-info {
        .stat-value {
          font-size: 24px;
          font-weight: bold;
          color: #333;
          margin-bottom: 4px;
        }
        
        .stat-label {
          font-size: 14px;
          color: #666;
        }
      }
    }
  }
  
  .card-header {
    font-weight: bold;
    color: #333;
  }
  
  .chart-container {
    height: 300px;
    
    .chart-placeholder {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100%;
      color: #999;
      
      p {
        margin-top: 16px;
        font-size: 14px;
      }
    }
  }
}
</style>
